<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<?php
	$d1 = "";
	$jieguo = 0;
	$yunsuanfu = "";
	if( !empty($_POST)){
		$d1 = $_POST['data1'];
		$yunsuanfu = $_POST["yunsuanfu"];
		switch ($yunsuanfu){
			case "1":
				$jieguo = decbin($d1);
				break;
			case "2":
				$jieguo = decoct($d1);
				break;
			case "3":
				$jieguo = dechex($d1);
				break;
			case "4":
				$jieguo = bindec($d1);
				break;
			case "5":
				$jieguo = octdec($d1);
				break;
			case "6":
				$jieguo = hexdec($d1);
				break;
		}
	}
	
?>
进制转换
<hr />
<form action="" method="post">
		<input type="text" name="data1" value="<?php echo $d1; ?>"/>
		<select name="yunsuanfu">
			<option value="1" <?php if($yunsuanfu=="1"){ echo 'selected="selected"';} ?>>10to2</option>
			<option value="2" <?php if($yunsuanfu=="2"){ echo 'selected="selected"';} ?>>10to8</option>
			<option value="3" <?php if($yunsuanfu=="3"){ echo 'selected="selected"';} ?>>10to16</option>
			<option value="4" <?php if($yunsuanfu=="4"){ echo 'selected="selected"';} ?>>2to10</option>
			<option value="5" <?php if($yunsuanfu=="5"){ echo 'selected="selected"';} ?>>8to10</option>
			<option value="6" <?php if($yunsuanfu=="6"){ echo 'selected="selected"';} ?>>16to10</option>
		</select>
		<input type="submit" name="转换"/>
		<input type="text" name="result" value="<?php echo $jieguo; ?>" />
	</form>
</body>
</html>